<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="170px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item
									v-if="this.early_Data.PDPOPFLG001 == 'UNIFORM'"
									label="区域内土地覆盖的比例"
									prop="CHFRACLD001"
								>
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHFRACLD001"
									></el-input>
								</el-form-item>
								<el-form-item
									v-if="this.early_Data.PDPOPFLG001 == 'UNIFORM'"
									label="土地中，耕地的比例"
									prop="CHFRCFRM001"
								>
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHFRCFRM001"
									></el-input>
								</el-form-item>
								<el-form-item
									v-if="this.early_Data.PDPOPFLG001 == 'UNIFORM'"
									label="耕地年均经济效益"
									prop="CHFRMPRD001"
								>
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHFRMPRD001"
									>
										<template slot="append">元/hectare</template>
									</el-input>
								</el-form-item>
								<el-form-item
									v-if="this.early_Data.PDPOPFLG001 == 'UNIFORM'"
									label="耕地年均产量比例"
									prop="CHDPFRCT001"
								>
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHDPFRCT001"
									></el-input>
								</el-form-item>
								<el-form-item label="作物的成本" prop="CHVALWF001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHVALWF001"
									>
										<template slot="append">元/hectare</template>
									</el-input>
								</el-form-item>
								<el-form-item label="作物成本增长比例" prop="CHFRFIM001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHFRFIM001"
									></el-input>
								</el-form-item>
								<el-form-item label="非农作物的成本" prop="CHVALWNF001">
									<el-input size="medium" class="mediumForm" v-model="ruleForm.CHVALWNF001">
										<template slot="append">元/hectare</template>
									</el-input>
								</el-form-item>
								<el-form-item label="非农作物成本增长比例" prop="CHFRNFIM001">
									<el-input
										size="medium"
										class="mediumForm"
										oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,10})?).*$/g, '$1')"
										v-model="ruleForm.CHFRNFIM001"
									></el-input>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button
						type="primary"
						:disabled="this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
						:loading="loading"
						@click="submitFun"
					>下一步</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import selectPara from "@/components/selectPara"
import commCheckbox from "@/components/commCheckbox"
import ImageCropper from "@/components/ImageCropper"
import FixBottomButton from "@/components/FixBottomButton"
import ueditor from "@/components/ueditor"
import textLength from "@/components/common/comp/textLength"
import { commPara } from "@/mixins/mixins"
import { mapState } from "vuex"
import Axios from "axios"

export default {
	name: "aboutUs",
	props: {
		basicDataF: Object,
	},
	mixins: [commPara],
	components: {
		selectPara,
		ImageCropper,
		textLength,
		commCheckbox,
		FixBottomButton,
		ueditor,
	},

	data() {
		var C10610 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-6 || value > 1.0) {
				callback(new Error("输入范围为[1.0E-6,1.0]"))
			} else {
				callback()
			}
		}
		var C00105 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1.0e5) {
				callback(new Error("输入范围为[0.0，1.0E+5]"))
			} else {
				callback()
			}
		}

		var C0010 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 1.0) {
				callback(new Error("输入范围为[0.0，1.0]"))
			} else {
				callback()
			}
		}
		var C106106 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-6 || value > 1.0e6) {
				callback(new Error("输入范围为[1.0E-6，1.0E+6]"))
			} else {
				callback()
			}
		}
		var CHDSCRTI001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 0.0 || value > 100000) {
				callback(new Error("输入范围为[0.0，100000]"))
			} else {
				callback()
			}
		}
		var CHDSCRLT001 = (rule, value, callback) => {
			if (value == "") {
				callback(new Error("输入值不能为空"))
			} else if (value < 1.0e-20 || value > 1.0e5) {
				callback(new Error("输入范围为[1.0E-20,1.0E+5]"))
			} else {
				callback()
			}
		}

		return {
			activeTab: "5",

			dialogVisible: false,
			ruleForm: {
				CHFRACLD001: "0.95",
				CHFRCFRM001: "0.382",
				CHFRMPRD001: "371.0",
				CHDPFRCT001: "0.198",
				CHVALWF001: "2613.0",
				CHFRFIM001: "0.25",
				CHVALWNF001: "84000.0",
				CHFRNFIM001: "0.8",
			},
			rules: {
				CHFRACLD001: [
					{
						validator: C10610,
						trigger: ["change", "blur"],
					},
				],
				CHFRCFRM001: [
					{
						validator: C10610,
						trigger: ["change", "blur"],
					},
				],
				CHFRMPRD001: [
					{
						validator: C00105,
						trigger: ["change", "blur"],
					},
				],
				CHDPFRCT001: [
					{
						validator: C0010,
						trigger: ["change", "blur"],
					},
				],
				CHVALWF001: [
					{
						validator: C106106,
						trigger: ["change", "blur"],
					},
				],
				CHFRFIM001: [
					{
						validator: C0010,
						trigger: ["change", "blur"],
					},
				],
				CHVALWNF001: [
					{
						validator: C106106,
						trigger: ["change", "blur"],
					},
				],
				CHFRNFIM001: [
					{
						validator: C0010,
						trigger: ["change", "blur"],
					},
				],
			},

			loading: false,
		}
	},
	computed: {
		...mapState({
			basic_Data: (state) => state.token.basic_Data,
			early_Data: (state) => state.token.early_Data,
			longterm_Data: (state) => state.token.longterm_Data,
		}),
	},
	mounted() {
		this.setData()
	},
	methods: {
		setData() {
			this.ruleForm.CHFRACLD001 = this.longterm_Data.CHFRACLD001
				? this.longterm_Data.CHFRACLD001.toString()
				: "0.95"
			this.ruleForm.CHFRCFRM001 = this.longterm_Data.CHFRCFRM001
				? this.longterm_Data.CHFRCFRM001.toString()
				: "0.382"
			this.ruleForm.CHFRMPRD001 = this.longterm_Data.CHFRMPRD001
				? this.longterm_Data.CHFRMPRD001.toString()
				: "371.0"
			this.ruleForm.CHDPFRCT001 = this.longterm_Data.CHDPFRCT001
				? this.longterm_Data.CHDPFRCT001.toString()
				: '0.198'
			this.ruleForm.CHVALWF001 = this.longterm_Data.CHVALWF001
				? this.longterm_Data.CHVALWF001.toString()
				: 2813.0
			this.ruleForm.CHFRFIM001 = this.longterm_Data.CHFRFIM001
				? this.longterm_Data.CHFRFIM001.toString()
				: "0.25"
			this.ruleForm.CHVALWNF001 = this.longterm_Data.CHVALWNF001
				? this.longterm_Data.CHVALWNF001.toString()
				: 84000
			this.ruleForm.CHFRNFIM001 = this.longterm_Data.CHFRNFIM001
				? this.longterm_Data.CHFRNFIM001.toString()
				: 0.8
		},
		submitFun() {
			//保存
			this.$refs.form.validate((valid) => {
				if (valid) { 
					let tempdata = JSON.parse(
						JSON.stringify(this.longterm_Data)
					) 
					if (this.early_Data.PDPOPFLG001 == "UNIFORM") {
						tempdata.CHFRACLD001 = parseFloat(
							this.ruleForm.CHFRACLD001
						)
						tempdata.CHFRCFRM001 = parseFloat(
							this.ruleForm.CHFRCFRM001
						)
						tempdata.CHFRMPRD001 = parseFloat(
							this.ruleForm.CHFRMPRD001
						)
						tempdata.CHDPFRCT001 = parseFloat(
							this.ruleForm.CHDPFRCT001
						)
					} 
					tempdata.CHVALWF001 = parseFloat(this.ruleForm.CHVALWF001)
					tempdata.CHFRFIM001 = parseFloat(this.ruleForm.CHFRFIM001) 
					tempdata.CHVALWNF001 = parseFloat(this.ruleForm.CHVALWNF001)
					tempdata.CHFRNFIM001 = parseFloat(this.ruleForm.CHFRNFIM001)
					tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_longterm_Data", tempdata) 
					let params = {
						batchid: this.$route.query.id,
						batchinfo: "CHANGQI",
						submitjson: JSON.stringify(tempdata),
					} 
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => { 
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "保存失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "保存成功！",
									type: "success",
								})
							}
						})
						.catch((err) => {
							console.log(err)
						})
					this.$emit("changeActiveTab", this.activeTab)
					this.$store.dispatch(
						"change_longterm_showTab",
						this.activeTab
					)
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>